//
//  BaseTabBarController.swift
//  SinaBlog
//
//  Created by 有何不可 on 15/12/30.
//  Copyright © 2015年 有何不可. All rights reserved.
//

import UIKit

class BaseTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        let tabbar = TabBar()
        
        setValue(tabbar, forKeyPath: "TabBar")
        
        addChildViewController()
        
        tabbar.button.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    func login() {
        
        print("发布微博界面")
        
        let vc = PublishBlogController()
        
        vc.model = OauthViewModel.sharedInstance.model
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    private func addChildViewController() {
        
        addChildViewController("首页", imageName: "home", childController: HomeController())
        addChildViewController("消息", imageName: "message", childController: MessageController())
        addChildViewController("发现", imageName: "discover", childController: FindViewController())
        addChildViewController("我的", imageName: "profile", childController: SettingController())
    }
    
    private func addChildViewController(title: String, imageName: String, childController: UIViewController?) {
        
        let nav = UINavigationController(rootViewController: childController!)
        
        childController?.title = title
        
        nav.tabBarItem.image = UIImage(named: "tabbar_\(imageName)")
        
        nav.tabBarItem.selectedImage = UIImage(named: "tabbar_\(imageName)_highlighted")
        
        addChildViewController(nav)
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
